home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-09-10 | 5.4 KB | 197 lines | [TEXT/MMCC] |
- // File "sample win.c" -
-
- #include "main.h"
- #include "floaters.h"
- #include "prefs.h"
- #include "sample drag.h"
- #include "sample win.h"
-
- #include "mdg.h"
-
- // ***********************************************************************************
- // Global Declarations
-
- extern GlobalsRec glob;
-
-
- // ***********************************************************************************
- // ***********************************************************************************
-
- WindowPtr NewSampleWindow() {
- static short count = 0, **prefCount;
- Rect bounds;
- WindowPtr win;
- Str255 textBuff = "\pSample Window ", altBuff;
- StringPtr winTextPtr;
-
- // Demo the prefs functions by incrementing the Window #
- if (prefCount = (short **) GetPrefs('WCnt', 1)) {
- count = ++(**prefCount);
- WritePrefs((Handle) prefCount, 'WCnt', 1);
- DisposeHandle((Handle) prefCount);
- }
- else if (prefCount = (short **) NewHandle(sizeof(**prefCount))) {
- **prefCount = ++count;
- WritePrefs((Handle) prefCount, 'WCnt', 1);
- DisposeHandle((Handle) prefCount);
- }
- else count++;
-
- // Setup the Window Title String
- NumToString(count, altBuff);
- BlockMove(altBuff+1, textBuff + textBuff[0] + 1, altBuff[0]);
- textBuff[0] += altBuff[0];
-
- SetRect(&bounds, qd.screenBits.bounds.left, qd.screenBits.bounds.bottom-kTaskbarHeight/*kTaskbarScreenBottomMargin*/, qd.screenBits.bounds.right, qd.screenBits.bounds.bottom+1/*+kTaskbarHeight-kTaskbarScreenBottomMargin*/);
- // OffsetRect(&bounds, (count-1) % 3 * 40, (count-1) % 3 * 40);
- win = NewFloater(0, &bounds, textBuff, TRUE, /*2048*/ 2, (WindowPtr) -1, TRUE, 0, 0,
- SampleWindowEventHandler, DisposeSampleWindow);
-
- // Apply some text to draw for update routines
- if (win)
- {
- {
- GrafPtr savedPort;
-
- // remember this window (forever)
- gTaskbarWindow = win;
-
- // quickly draw the gray background
- GetPort(&savedPort);
- SetPort(win);
-
- RGBBackColor(&kBgGrayColor);
- EraseRect(&win->portRect);
- DrawMacOSIcon();
- SetPort(savedPort);
-
- // build the list of processes
- UpdateProcessArray();
-
- gTaskbarVisible = TRUE;
-
- // make my process invisible
-
- }
-
- /* SetSampleWindowText(win,
- "\pAppeWin 2.0: A free demo program and source code by Matt Slot (fprefect@umich.edu) \
- that shows off TSM Floaters.\r\rThe latest version is free to look at or use, and can \
- be downloaded from your local Sumex or Mac-Archives mirror site.");
- */
- }
-
- if (win && glob.hasDragMgr) SetupDragHandlers(win);
-
- return(win);
- }
-
- // ***********************************************************************************
- // ***********************************************************************************
-
- void DisposeSampleWindow(WindowPtr win) {
- StringPtr winTextPtr;
-
- if (winTextPtr = (StringPtr) GetWRefCon(win)) DisposePtr((Ptr) winTextPtr);
- DisposeFloater(win);
-
- // For a background only app, this will cause us to quit when the user
- // closes the last floater. Its your choice if you want this to happen.
- if (glob.bkgdOnly && ! GetIndFloater(1, FALSE)) glob.quitting = TRUE;
- }
-
- // ***********************************************************************************
- // ***********************************************************************************
-
- void SampleWindowEventHandler(EventRecord *theEvent, WindowPtr win) {
- Rect destRect;
- GrafPtr savePort;
- StringPtr winTextPtr;
-
- switch(theEvent->what) {
- case nullEvent:
- break;
- case mouseDown: {
- // The Window part has already been found and forwarded to us
- short thePart = theEvent->message;
-
- switch(thePart) {
- case inContent:
- DoClickInTaskbar(theEvent, win);
- break;
- case inGrow:
- break;
- case inGoAway:
- if (TrackGoAway(win, theEvent->where))
- DisposeSampleWindow(win);
- break;
- case inZoomIn:
- break;
- case inZoomOut:
- break;
- }
- break;
- }
- case keyDown:
- case autoKey:
- break;
- case updateEvt: {
- GetPort(&savePort);
- SetPort(win);
- BeginUpdate(win);
-
- UpdateProcessArray();
- DrawTaskbar(win);
-
- /*
- // Draw something cool!
- destRect = win->portRect;
- EraseRect(&destRect);
- InsetRect(&destRect, 4, 4);
- TextFont(1); TextSize(9);
- if (winTextPtr = GetSampleWindowText(win))
- TextBox(winTextPtr+1, winTextPtr[0], &destRect, teFlushDefault);
- TextFont(0); TextSize(0);
- */
- EndUpdate(win);
- SetPort(savePort);
- break;
- }
- }
- }
-
- // ***********************************************************************************
- // ***********************************************************************************
-
- void SetSampleWindowText(WindowPtr win, StringPtr winText) {
- Boolean dirty = FALSE;
- Ptr storage = (Ptr) GetWRefCon(win);
- GrafPtr savePort;
-
- if (! storage) { storage = NewPtr(sizeof(Str255)); dirty = TRUE; }
- if (! storage) return;
-
- if (winText && ! EqualString(winText, (StringPtr) storage, 0, 0)) dirty = TRUE;
- BlockMove((winText && winText[0]) ? winText : "\p", storage, sizeof(Str255));
- SetWRefCon(win, (long) storage);
-
- // Force a redraw after changing content
- if (dirty) {
- GetPort(&savePort);
- SetPort(win);
- InvalRect(&win->portRect);
- SetPort(savePort);
- }
- }
-
- // ***********************************************************************************
- // ***********************************************************************************
-
- StringPtr GetSampleWindowText(WindowPtr win) {
- Ptr storage = (Ptr) GetWRefCon(win);
- StringPtr winText;
-
- winText = (storage && ((StringPtr) storage[0])) ? ((StringPtr) storage) : "\p<No Data>";
- return(winText);
- }
-